﻿using System;
using System.Windows.Forms;

namespace ShadeTree.Binding.Elements
{
    public class CheckboxElement : BoundScreenElement<CheckBox, bool>
    {
        public CheckboxElement(Accessor accessor, CheckBox control) : base(accessor, control)
        {
            control.CheckedChanged += control_CheckedChanged;
            Alias = control.Text;
        }

        private void control_CheckedChanged(object sender, EventArgs e)
        {
            elementValueChanged();
        }


        protected override bool getValueFromControl()
        {
            return BoundControl.Checked;
        }

        protected override void resetControl(bool originalValue)
        {
            BoundControl.Checked = originalValue;
        }

        protected override void tearDown()
        {
            BoundControl.CheckedChanged -= control_CheckedChanged;
        }
    }
}